/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nationsim.input;

import java.util.Hashtable;
import javax.swing.JOptionPane;
import nationsim.components.nation.NationStateValues;

/**
 * State that holds all the values for the UI Bar Input, this should eventually
 * be passed to the UserInputReader.
 * @author CJ
 */
public class UserInputBarState {

    protected Hashtable storage;

    public UserInputBarState(){
        this.storage = new Hashtable(NationStateValues.USER_SET.length);
        for(int i = 0; i < NationStateValues.USER_SET.length; ++i)
            this.storage.put(i, NationStateValues.VALUES_DEFAULT[NationStateValues.USER_SET[i]]);
    }

    public void update(String command){
        System.out.println(command);
        if(command.equals("FITax"))
            updateFITax();
    }

    protected void updateFITax(){
        String s = (String) JOptionPane.showInputDialog("Please enter desired Federal Income Interest",
               storage.get(findUserPos(NationStateValues.FEDERAL_INCOME_TAX)));
        if(s != null)
            this.storage.put(findUserPos(NationStateValues.FEDERAL_INCOME_TAX), s);
    }

    protected int findUserPos(int key){
        for(int i = 0;i < NationStateValues.USER_SET.length; ++i){
            if(NationStateValues.USER_SET[i] == key)
                return i;
        }
        throw new IllegalArgumentException("In Find User Pos, Key wasn't found in User Set!!!");
    }
}
